/**
 * 
 */
package com.study.property;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;


/**
 * @author Administrator
 * @date 2019年4月27日
 */
public class PropertyTest {

	public static void main(String[] args) throws FileNotFoundException, IOException{
		testDemo1();
	}
	
	public static void testDemo1() throws FileNotFoundException, IOException{
		Properties properties = new Properties();
		//System.out.println(new File(".").getAbsolutePath());
		//properties.load(new FileInputStream("D:\\06java\\workspace\\study-demo\\src\\main\\resources\\test.properties"));
		properties.load(new FileInputStream(".\\src\\main\\resources\\test.properties"));
		//properties.load(PropertyTest.class.getClassLoader().getResourceAsStream ("test.properties"));
		Set<String> stringPropertyNames = properties.stringPropertyNames();
		for(String key : stringPropertyNames){
			System.out.println(key + "=" + properties.getProperty(key));
		}
		
		
		///保存属性到b.properties文件
        FileOutputStream oFile = new FileOutputStream(".\\src\\main\\resources\\new_test.properties", true);//true表示追加打开
        properties.setProperty("phone", "10086");
        properties.store(oFile, "The New properties file");
        oFile.close();
	}
}
